<?php
/**
 * Joomla! 1.5 component jhtraq
 *
 * @version $Id: view.html.php 2010-03-09 08:28:06 svn $
 * @author JHShop
 * @package Joomla
 * @subpackage jhtraq
 * @license GNU/GPL
 *
 * Traq type system for Joomla
 *
 * This component file was created using the Joomla Component Creator by Not Web Design
 * http://www.notwebdesign.com/joomla_component_creator/
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the jhtraq component
 */
class JhtraqViewMilestone extends JView {
	function display($tpl = null) {
		$model =& JhtraqHelper::getModel('jhtraq');
		$project = JRequest::getVar('project');
		//echo $project;
		$this->project = $model->getProjectBySlug($project);
		
		$db =& JFactory::getDBO();
		$db->setQuery("SELECT * FROM #__jhtraq_milestones WHERE slug='".$db->getEscaped(JRequest::getVar('milestone'))."' AND project_id='".$this->project->id."' LIMIT 1");
		$milestone = $db->loadAssoc();
		
		$milestone['tickets'] = array();
		$milestone['tickets']['open'] = 0;
		$milestone['tickets']['closed'] = 0;
		$db->setQuery("Select count(*) as cnt,closed from #__jhtraq_tickets where milestone_id='".$milestone['id']."' AND project_id='".$this->project->id."' group by closed");
		$rows = $db->loadAssocList();
		foreach($rows as $row)
		{
			if($row['closed'] == '1')
			{
				$milestone['tickets']['closed'] = $row['cnt'];
			}else{
				$milestone['tickets']['open'] = $row['cnt'];
			}
		}
		$milestone['tickets']['total'] = $milestone['tickets']['closed'] + $milestone['tickets']['open'];
		$milestone['tickets']['percent'] = array(
		'open' => ($milestone['tickets']['open'] ? JhtraqHelper::getpercent($milestone['tickets']['open'],$milestone['tickets']['total']) : 0),
		'closed' => JhtraqHelper::getpercent($milestone['tickets']['closed'],$milestone['tickets']['total'])
				   );
		$this->milestone = $milestone;
		
        parent::display($tpl);
    }
}
?>